{% macro giscus(search_term, lang) %}
    {% if lang != "en" %}
        {% set category = "Post Comments (translated)" %}
        {% set category_id = "DIC_kwDOAlvePc4CPg4c" %}
        {% set category_path = "post-comments-translated" %}
    {% else %}
        {% set category = "Post Comments" %}
        {% set category_id = "MDE4OkRpc2N1c3Npb25DYXRlZ29yeTMzMDE4OTg1" %}
        {% set category_path = "post-comments" %}
    {% endif %}

    {% if search_term is number %}
        {% set discussion_url = "https://github.com/phil-opp/blog_os/discussions/" ~ search_term %}
    {% else %}
        {% set search_term_encoded = `"` ~ search_term ~ `"` ~ ` in:title` | urlencode %}
        {% set discussion_url = `https://github.com/phil-opp/blog_os/discussions/categories/` ~ category_path ~ `?discussions_q=` ~ search_term_encoded %}
    {% endif %}

    <p class="comment-note">
        {{ trans(key="comment_note", lang=lang) | replace(from="_discussion_url_", to=discussion_url) | safe }}
    </p>

    <div class="giscus"></div>

    <script src="https://giscus.app/client.js"
        data-repo="phil-opp/blog_os"
        data-repo-id="MDEwOlJlcG9zaXRvcnkzOTU3NTEwMQ=="
        data-category="{{ category }}"
        data-category-id="{{ category_id }}"
    {% if search_term is number %}
        data-mapping="number"
    {% else %}
        data-mapping="specific"
    {% endif %}
        data-term="{{ search_term }}"
        data-reactions-enabled="1"
        data-emit-metadata="1"
        data-theme="preferred_color_scheme"
        data-lang="{{ lang }}"
        crossorigin="anonymous"
        async>
    </script>

    <p class="comment-directly-on-github">
        Instead of authenticating the <a href="https://giscus.app">giscus</a> application, you can also comment directly <a href="{{ discussion_url | safe }}"><em>on GitHub</em></a>.
    </p>
{% endmacro giscus %}
